﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JobSiteStarterKit.DAL;
using JobSiteStarterKit.ENUM;
namespace JobSiteStarterKit.BOL
{
    /// <summary>
    /// Summary description for JobSearch
    /// </summary>
    /// 

    public class JobSearch
    {
        DBAccess objDb;
        JobSearchBy searchBy;
        public JobSearch()
        {
            objDb = new DBAccess();
            
        }

        public DataSet SearchBy(JobSearchBy searchby, string parameter,params string[] optional )
        {
            DataSet ds = new DataSet();
            string proc="";
            if (searchby == JobSearchBy.CategorySearch)
            {
                proc = "JobsDb_JobPostings_SearchByCategory_NonExpiredJobs";
                objDb.CommandText = proc;
                objDb.AddParameter("@CatID", Convert.ToInt32(parameter));
            }
            else
            {
                proc = "AdvanceJobSearch";
                objDb.CommandText = proc;
                
                if(optional[0] != null)
                    objDb.AddParameter("@keyword", optional[0]);
                if (optional[1] != null)
                    objDb.AddParameter("@Location", optional[1]);
                if (optional[2] != null)
                    objDb.AddParameter("@FunctionalArea", optional[2]);

               // objDb.AddParameter("@ExpId", optional[0]);


            }
            ds = objDb.ExecuteDataSet();
            return ds;
        }

        public int ApplyJobs(string PostingIds, string UserName)
        {
            using (DBAccess db = new DBAccess())
            {
                db.CommandText = "ApplyJobs";
                db.AddParameter("@Value", PostingIds);
                db.AddParameter("@username", UserName);
                System.Data.SqlClient.SqlParameter prmOutput = new System.Data.SqlClient.SqlParameter("@iRegister", SqlDbType.Int);
                prmOutput.Direction = ParameterDirection.Output;
                db.AddParameter(prmOutput);
                db.ExecuteNonQuery();
                if (Convert.ToInt32(prmOutput.Value) < 0)
                {
                  return -1;
                }
               
                
            }
            return 1;
        }

        public void SaveJobs(string PostingIds, string username)
        {
            using (DBAccess db = new DBAccess())
            {
                db.CommandText = "SaveJobs";
                db.AddParameter("@Value", PostingIds);
                db.AddParameter("@username", username);
                db.ExecuteNonQuery();

            }
        }

        public DataSet AdvanceSearch()
        {
            DataSet ds = new DataSet();

            return ds;
        }

    }
}